prefix = /usr/local
exec_prefix = ${prefix}
libdir = -L${exec_prefix}/lib -L/usr/local/ssl/lib64
lib = -lpbc -lgmp -lm -lssl -lcrypto -lpthread -lrt -ldl
includedir = -I${prefix}/include -I/usr/local/ssl/include/

DEBUG = -g -O0

RELEASE = -O3 -ftree-vectorize -msse2
#RELEASE = -g -O0
CC = g++
CFLAGS = $(RELEASE) -Wall  $(includedir)
LDFLAGS = $(RELEASE) -Wall $(libdir) -static
LDFLAGSST = $(RELEASE) -Wall $(libdir)
DISTNAME = setint
SOURCES = crypto_tool.o mpz_tool.o basic_tool.o randomnumber.o memreuse.o rsakeygen.o \
	error.o ib.o ib_udp_wrapper.o  config.o hashtable.o udpresponse.o udprequest.o \
	udpagent.o server_udp_wrapper.o server.o client_udp_wrapper.o \
	sql_parser.o

EXE = rsakeygen encrypt_database client_main server_main ib_main dsakeygen


.Phony: clean


all: encrypt_database rsakeygen dsakeygen ib_main client_main server_main TAGS


rsakeygen: $(SOURCES) rsakeygen_main.o
	$(CC) -o $@ $(LDFLAGS) $(includedir) $^ $(lib)

dsakeygen: $(SOURCES) dsakeygen.o
	$(CC) -o $@ $(LDFLAGS) $(includedir) $^ $(lib)

encrypt_database: $(SOURCES) encrypt_database.o
	$(CC) -o $@ $(LDFLAGS) $(includedir) $^ $(lib)


client_main: $(SOURCES) client_main.o
	$(CC) -o $@ $(LDFLAGS) $(includedir) $^ $(lib)

server_main: $(SOURCES) server_main.o
	$(CC) -o $@ $(LDFLAGS) $(includedir) $^ $(lib)

ib_main: $(SOURCES) ib_main.o
	$(CC) -o $@ $(LDFLAGS) $(includedir) $^ $(lib)

test: $(SOURCES) test.o
	$(CC) -o $@ $(LDFLAGS) $(includedir) $^ $(lib)

TAGS: $(SOURCES)
	etags *.cc *.h

# export2mysql: $(SOURCES) export2mysql.o
# 	$(CC) -o $@ $(LDFLAGS) $(includedir) $^ $(lib)

%.o: %.cc
	$(CC) -c -o $@ $< $(CFLAGS)

clean:
	rm -rf *.o *.a $(DISTNAME) *.tar.gz TAGS *~ $(EXE)

install:
	cp encrypt_database ~/encrypt_database/
	cp server_main ~/ibserver/
	cp ib_main ~/ibserver/
